const app = getApp()
Page({
  data: {
    hasUserInfo: false,
    avatarUrl:"",
    nickName:"",
    hasUserInformation:false,
    isAdmin:false
  },
  onLoad() {
  },
  login(e) {
    wx.getUserProfile({
      desc: '展示用户信息',
      success: (res) => {
        app.globalData.nickName=res.userInfo.nickName
        app.globalData.avatarUrl=res.userInfo.avatarUrl
        this.setData({
          hasUserInfo:true,
          avatarUrl:res.userInfo.avatarUrl,
          nickName:res.userInfo.nickName
        })
      }
    })
  },
  onShareAppMessage(res){
 
  },
  onShareTimeline(){
    
  },
  onShow(){
    wx.cloud.callFunction({ name: 'function', data: { type: "getEnv" } }).then(res => {
      var data=res.result.user.data
      app.globalData.hasUserInformation=(data.length>0)?true:false
      app.globalData.openId=res.result.openid
      var isAdmin=false
      if(data.length>0)isAdmin=data[0].isAdmin
       this.setData({
         hasUserInformation:app.globalData.hasUserInformation,
        isAdmin:isAdmin
      })
    })
  }
})